home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / utils / Environment.as next >
Encoding:
Text File  |  2011-10-17  |  7.9 KB  |  319 lines

  1. package com.google.analytics.utils
  2. {
  3.    import com.google.analytics.core.ga_internal;
  4.    import com.google.analytics.debug.DebugConfiguration;
  5.    import com.google.analytics.external.HTMLDOM;
  6.    import flash.system.Capabilities;
  7.    import flash.system.Security;
  8.    import flash.system.System;
  9.    
  10.    use namespace ga_internal;
  11.    
  12.    public class Environment
  13.    {
  14.        
  15.       
  16.       private var _dom:HTMLDOM;
  17.       
  18.       private var _appName:String;
  19.       
  20.       private var _debug:DebugConfiguration;
  21.       
  22.       private var _appVersion:Version;
  23.       
  24.       private var _url:String;
  25.       
  26.       private var _protocol:Protocols;
  27.       
  28.       private var _userAgent:UserAgent;
  29.       
  30.       public function Environment(url:String = "", app:String = "", version:String = "", debug:DebugConfiguration = null, dom:HTMLDOM = null)
  31.       {
  32.          var v:Version = null;
  33.          super();
  34.          if(app == "")
  35.          {
  36.             if(isAIR())
  37.             {
  38.                app = "AIR";
  39.             }
  40.             else
  41.             {
  42.                app = "Flash";
  43.             }
  44.          }
  45.          if(version == "")
  46.          {
  47.             v = flashVersion;
  48.          }
  49.          else
  50.          {
  51.             v = Version.fromString(version);
  52.          }
  53.          _url = url;
  54.          _appName = app;
  55.          _appVersion = v;
  56.          _debug = debug;
  57.          _dom = dom;
  58.       }
  59.       
  60.       public function isAIR() : Boolean
  61.       {
  62.          return playerType == "Desktop" && Security.sandboxType.toString() == "application";
  63.       }
  64.       
  65.       public function get screenWidth() : Number
  66.       {
  67.          return Capabilities.screenResolutionX;
  68.       }
  69.       
  70.       public function get playerType() : String
  71.       {
  72.          return Capabilities.playerType;
  73.       }
  74.       
  75.       public function get locationSearch() : String
  76.       {
  77.          var _search:String = _dom.search;
  78.          if(_search)
  79.          {
  80.             return _search;
  81.          }
  82.          return "";
  83.       }
  84.       
  85.       public function get protocol() : Protocols
  86.       {
  87.          if(!_protocol)
  88.          {
  89.             _findProtocol();
  90.          }
  91.          return _protocol;
  92.       }
  93.       
  94.       public function get flashVersion() : Version
  95.       {
  96.          return Version.fromString(Capabilities.version.split(" ")[1],",");
  97.       }
  98.       
  99.       public function get userAgent() : UserAgent
  100.       {
  101.          if(!_userAgent)
  102.          {
  103.             _userAgent = new UserAgent(this,appName,appVersion.toString(4));
  104.          }
  105.          return _userAgent;
  106.       }
  107.       
  108.       public function get languageEncoding() : String
  109.       {
  110.          var _charset:String = null;
  111.          if(System.useCodePage)
  112.          {
  113.             _charset = _dom.characterSet;
  114.             if(_charset)
  115.             {
  116.                return _charset;
  117.             }
  118.             return "-";
  119.          }
  120.          return "UTF-8";
  121.       }
  122.       
  123.       public function get appName() : String
  124.       {
  125.          return _appName;
  126.       }
  127.       
  128.       public function get screenColorDepth() : String
  129.       {
  130.          var color:String = null;
  131.          switch(Capabilities.screenColor)
  132.          {
  133.             case "bw":
  134.                color = "1";
  135.                break;
  136.             case "gray":
  137.                color = "2";
  138.                break;
  139.             case "color":
  140.             default:
  141.                color = "24";
  142.          }
  143.          var _colorDepth:String = _dom.colorDepth;
  144.          if(_colorDepth)
  145.          {
  146.             color = _colorDepth;
  147.          }
  148.          return color;
  149.       }
  150.       
  151.       private function _findProtocol() : void
  152.       {
  153.          var URL:String = null;
  154.          var test:String = null;
  155.          var p:Protocols = Protocols.none;
  156.          if(_url != "")
  157.          {
  158.             URL = _url.toLowerCase();
  159.             test = URL.substr(0,5);
  160.             switch(test)
  161.             {
  162.                case "file:":
  163.                   p = Protocols.file;
  164.                   break;
  165.                case "http:":
  166.                   p = Protocols.HTTP;
  167.                   break;
  168.                case "https":
  169.                   if(URL.charAt(5) == ":")
  170.                   {
  171.                      p = Protocols.HTTPS;
  172.                   }
  173.                   break;
  174.                default:
  175.                   _protocol = Protocols.none;
  176.             }
  177.          }
  178.          var _proto:String = _dom.protocol;
  179.          var proto:String = (p.toString() + ":").toLowerCase();
  180.          if(_proto && _proto != proto && Boolean(_debug))
  181.          {
  182.             _debug.warning("Protocol mismatch: SWF=" + proto + ", DOM=" + _proto);
  183.          }
  184.          _protocol = p;
  185.       }
  186.       
  187.       public function get locationSWFPath() : String
  188.       {
  189.          return _url;
  190.       }
  191.       
  192.       public function get platform() : String
  193.       {
  194.          var p:String = Capabilities.manufacturer;
  195.          return p.split("Adobe ")[1];
  196.       }
  197.       
  198.       public function get operatingSystem() : String
  199.       {
  200.          return Capabilities.os;
  201.       }
  202.       
  203.       public function set appName(value:String) : void
  204.       {
  205.          _appName = value;
  206.          userAgent.applicationProduct = value;
  207.       }
  208.       
  209.       ga_internal function set url(value:String) : void
  210.       {
  211.          _url = value;
  212.       }
  213.       
  214.       public function get referrer() : String
  215.       {
  216.          var _referrer:String = _dom.referrer;
  217.          if(_referrer)
  218.          {
  219.             return _referrer;
  220.          }
  221.          if(protocol == Protocols.file)
  222.          {
  223.             return "localhost";
  224.          }
  225.          return "";
  226.       }
  227.       
  228.       public function isInHTML() : Boolean
  229.       {
  230.          return Capabilities.playerType == "PlugIn";
  231.       }
  232.       
  233.       public function get language() : String
  234.       {
  235.          var _lang:String = _dom.language;
  236.          var lang:String = Capabilities.language;
  237.          if(_lang)
  238.          {
  239.             if(_lang.length > lang.length && _lang.substr(0,lang.length) == lang)
  240.             {
  241.                lang = _lang;
  242.             }
  243.          }
  244.          return lang;
  245.       }
  246.       
  247.       public function get domainName() : String
  248.       {
  249.          var URL:String = null;
  250.          var str:String = null;
  251.          var end:int = 0;
  252.          if(protocol == Protocols.HTTP || protocol == Protocols.HTTPS)
  253.          {
  254.             URL = _url.toLowerCase();
  255.             if(protocol == Protocols.HTTP)
  256.             {
  257.                str = URL.split("http://").join("");
  258.             }
  259.             else if(protocol == Protocols.HTTPS)
  260.             {
  261.                str = URL.split("https://").join("");
  262.             }
  263.             end = str.indexOf("/");
  264.             if(end > -1)
  265.             {
  266.                str = str.substring(0,end);
  267.             }
  268.             return str;
  269.          }
  270.          if(protocol == Protocols.file)
  271.          {
  272.             return "localhost";
  273.          }
  274.          return "";
  275.       }
  276.       
  277.       public function set userAgent(custom:UserAgent) : void
  278.       {
  279.          _userAgent = custom;
  280.       }
  281.       
  282.       public function set appVersion(value:Version) : void
  283.       {
  284.          _appVersion = value;
  285.          userAgent.applicationVersion = value.toString(4);
  286.       }
  287.       
  288.       public function get screenHeight() : Number
  289.       {
  290.          return Capabilities.screenResolutionY;
  291.       }
  292.       
  293.       public function get locationPath() : String
  294.       {
  295.          var _pathname:String = _dom.pathname;
  296.          if(_pathname)
  297.          {
  298.             return _pathname;
  299.          }
  300.          return "";
  301.       }
  302.       
  303.       public function get documentTitle() : String
  304.       {
  305.          var _title:String = _dom.title;
  306.          if(_title)
  307.          {
  308.             return _title;
  309.          }
  310.          return "";
  311.       }
  312.       
  313.       public function get appVersion() : Version
  314.       {
  315.          return _appVersion;
  316.       }
  317.    }
  318. }
  319.